﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using Caltech.Controllers;
using CaltechSoft.Service.EntityFW.Entity;
using CaltechSoft.Service.Repositories;
using LinqKit;

namespace Caltech.Models
{
    public class UserHistoryController : BaseApiController<UserHistory, UserHistoryModel, UserHistoryModel>
    {
        private IUserHistoryRepository m_UserRepository;

        public UserHistoryController(IUserHistoryRepository repository) :
            base(repository)
        {
            m_UserRepository = repository;
        }

        [HttpPost]
        [Route("api/userhistory/clearAll")]
        public IHttpActionResult ClearAll()
        {
            m_UserRepository.Clear();
            return Ok();
        }

        [HttpPost]
        [Route("api/userhistory/clear")]
        public IHttpActionResult Clear(ClearHistoryModel model)
        {
            if (model != null)
            {
                model.ToDate = new DateTime(model.ToDate.Year, model.ToDate.Month, model.ToDate.Day, 23, 59, 59);
                m_UserRepository.Clear(model.FromDate, model.ToDate);
            }
            return Ok();
        }
    }
}